package com.youku.plugins.shareV4.view.components
{
   import flash.display.Sprite;
   import com.youku.baseUI.BasePlayerButton;
   import com.youku.interfaces.IPlayerProxy;
   import flash.text.TextField;
   import com.youku.utils.AssetUtil;
   import flash.display.MovieClip;
   import com.youku.plugins.shareV4.ShareFont;
   import flash.text.TextFieldAutoSize;
   import com.youku.plugins.shareV4.ShareConstant;
   import flash.events.MouseEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.plugins.shareV4.view.events.SharePanelEvent;
   import com.youku.utils.StringUtil;
   import com.youku.utils.BaseUtil;
   
   public class SharePanel extends Sprite
   {
      
      public function SharePanel() {
         super();
      }
      
      private var _background:Sprite;
      
      private var _iconList:IconList;
      
      private var _closeButton:BasePlayerButton;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _shareTf:TextField;
      
      private var _titleTf:TextField;
      
      private var _transmitTf:TextField;
      
      private var _qrCodeTitleTf:TextField;
      
      private var _qrCodeInfoTf:TextField;
      
      private var _qrCode:QRCodeBox;
      
      private var _width:Number;
      
      private var _height:Number;
      
      public function init(param1:IPlayerProxy) : void {
         this._playerProxy = param1;
         this.createItems();
         this.addEvents();
      }
      
      private function createItems() : void {
         this._background = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         this._background.width = 330;
         this._background.height = 230;
         this._shareTf = AssetUtil.getTextField(false);
         this._shareTf.width = 50;
         this._shareTf.height = 25;
         this._shareTf.defaultTextFormat = ShareFont.FONT_TITLE;
         this._shareTf.text = "分享:";
         this._titleTf = AssetUtil.getTextField(false);
         this._titleTf.defaultTextFormat = ShareFont.FONT_COMMON_TITLE;
         this._titleTf.autoSize = TextFieldAutoSize.LEFT;
         this._transmitTf = AssetUtil.getTextField(false);
         this._transmitTf.width = 75;
         this._transmitTf.height = 25;
         this._transmitTf.defaultTextFormat = ShareFont.FONT_COMMON_TITLE;
         this._transmitTf.text = "分享到:";
         this._iconList = new IconList();
         this._iconList.init(this._playerProxy);
         this._qrCodeTitleTf = AssetUtil.getTextField(false);
         this._qrCodeTitleTf.width = 100;
         this._qrCodeTitleTf.height = 25;
         this._qrCodeTitleTf.defaultTextFormat = ShareFont.FONT_COMMON_TITLE;
         this._qrCodeTitleTf.text = "用手机看:";
         this._qrCode = new QRCodeBox(this._playerProxy);
         this._qrCodeInfoTf = AssetUtil.getTextField(false);
         this._qrCodeInfoTf.width = 160;
         this._qrCodeInfoTf.height = 75;
         this._qrCodeInfoTf.defaultTextFormat = ShareFont.FONT_COMMON;
         this._qrCodeInfoTf.text = ShareConstant.QRCODE_INFO;
         this._closeButton = AssetUtil.getStyleButton("P_CloseButton");
         AssetUtil.restoreButtonSize(this._closeButton);
         this.addChild(this._background);
         this.addChild(this._shareTf);
         this.addChild(this._titleTf);
         this.addChild(this._transmitTf);
         this.addChild(this._iconList);
         this.addChild(this._qrCodeTitleTf);
         this.addChild(this._qrCode);
         this.addChild(this._qrCodeInfoTf);
         this.addChild(this._closeButton);
         this.updateLayout();
      }
      
      public function setSize(param1:Number, param2:Number) : void {
         this._width = param1;
         this._height = param2;
         if(this.contains(this._background))
         {
            removeChild(this._background);
         }
         this._background.width = this._width;
         this._background.height = this._height;
         addChildAt(this._background,0);
         this.updateLayout();
      }
      
      override public function get width() : Number {
         return this._background.width;
      }
      
      override public function get height() : Number {
         return this._background.height;
      }
      
      private function updateLayout() : void {
         this._background.x = this._background.y = 0;
         this._shareTf.x = 10;
         this._shareTf.y = 7;
         this._titleTf.x = 32;
         this._titleTf.y = 34;
         this._transmitTf.x = 38;
         this._transmitTf.y = 68;
         this._iconList.x = 40;
         this._iconList.y = 95;
         this._qrCodeTitleTf.x = 38;
         this._qrCodeTitleTf.y = 133;
         this._qrCode.x = 40;
         this._qrCode.y = 160;
         this._qrCodeInfoTf.x = 157;
         this._qrCodeInfoTf.y = 183;
         this._closeButton.x = this._background.x + this._background.width - this._closeButton.width - 10;
         this._closeButton.y = 10;
      }
      
      private function addEvents() : void {
         this._closeButton.addEventListener(MouseEvent.CLICK,this.onCloseClick);
      }
      
      private function onCloseClick(param1:MouseEvent) : void {
         ReportUtil.sendUserActionLog(ReportUtil.SHARE_BOX_CLOSE_CLICK);
         this.dispatchEvent(new SharePanelEvent(SharePanelEvent.CLOSE));
      }
      
      public function show(param1:String, param2:Number) : void {
         this._qrCode.loadQRCode(param1,param2);
         if(param1 == "share")
         {
            this._titleTf.text = "【视频：" + StringUtil.getLimitWidthStr(this._playerProxy.playerData.videoTitle,130,this._titleTf.defaultTextFormat) + "】";
         }
         else
         {
            this._titleTf.text = "【视频：" + StringUtil.getLimitWidthStr(this._playerProxy.playerData.videoTitle,130,this._titleTf.defaultTextFormat) + "】" + BaseUtil.formatTime(param2) + "分钟";
         }
         this._iconList.updateData(param1,param2);
      }
      
      public function updateData() : void {
      }
   }
}
